﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Bronze.XXT.PhoneServer
{


	public abstract class MessageBody
	{
		public abstract byte[] GetBytes();
		public abstract MessageBody FromBytes(byte[] bytes);

		public string GetString(byte[] bytes, int index, int count)
		{
			var str = Encoding.Default.GetString(bytes, index, count);
			if (!string.IsNullOrEmpty(str))
			{
				return str.Trim();
			}
			return str;
		}
	}

	/// <summary>
	/// 学生卡登录请求
	/// 话机向服务器
	/// </summary>
	[Msg("01", true)]
	public class STDT_CARD_LOGIN_Request : MessageBody
	{
		/// <summary>
		/// 公话手机号 15
		/// </summary>
		public string Device_msisdn { get; set; }
		/// <summary>
		/// 公话ID 18
		/// </summary>
		public string Device_id { get; set; }
		/// <summary>
		/// 学生卡号 18
		/// </summary>
		protected string card_id { get; set; }


		public string CardID
		{
			get
			{
				return Utility.ConvertCardID(card_id);
			}
		}

		/// <summary>
		/// 学生ID 18
		/// </summary>
		public string student_id { get; set; }
		/// <summary>
		/// 请求时间 14
		/// </summary>
		public string request_time { get; set; }

		public override byte[] GetBytes()
		{
			return null;
		}
		public override MessageBody FromBytes(byte[] bytes)
		{
			this.Device_msisdn = Encoding.Default.GetString(bytes, 10, 15);
			this.Device_id = Encoding.Default.GetString(bytes, 25, 18);
			this.card_id = Encoding.Default.GetString(bytes, 43, 18);
			this.student_id = Encoding.Default.GetString(bytes, 61, 18);
			this.request_time = Encoding.Default.GetString(bytes, 79, 14);
			return this;
		}
	}
	/// <summary>
	/// 学生卡登录应答
	/// 服务器向话机
	/// </summary>
	[Msg("01", false)]
	public class STDT_CARD_LOGIN_Response : MessageBody
	{
		/// <summary>
		/// 学生卡是否有效 1
		/// 0 无效 (>0 有效)
		/// 1为学生卡
		/// 2为教师卡
		/// </summary>
		public string valid_flag { get; set; }
		/// <summary>
		/// 亲情号码个数 2
		/// </summary>
		public string Family_num { get; set; }
		/// <summary>
		/// 亲情号码列表 15
		/// </summary>
		public List<string> Family_msisdn { get; set; }
		/// <summary>
		/// 亲情号码关系（汉字形式） 4
		/// </summary>
		public List<string> Family_relation { get; set; }


		private string _message_num = "0000";
		/// <summary>
		/// 留言数目 4
		/// </summary>
		public string message_num
		{
			get
			{
				return _message_num.PadLeft(4, '0');
			}
			set
			{
				_message_num = value;
			}
		}
		/// <summary>
		/// 系统时间 14
		/// </summary>
		public string System_time
		{
			get { return DateTime.Now.ToString("yyyyMMddHHmmss"); }
		}

		public override byte[] GetBytes()
		{
			byte[] valid_flag_bytes = Encoding.Default.GetBytes(valid_flag);
			byte[] Family_num_bytes = Encoding.Default.GetBytes(Family_num.PadLeft(2, '0'));
			int Family_num_int = Convert.ToInt32(Family_num);
			byte[] Family_msisdn_bytes = new byte[Family_num_int * 15];
			byte[] Family_relation_bytes = new byte[Family_num_int * 4];
			for (int i = 0; i < Family_num_int; i++)
			{
				Encoding.Default.GetBytes(Family_msisdn[i]).CopyTo(Family_msisdn_bytes, i * 15);
				Encoding.Default.GetBytes(Family_relation[i]).CopyTo(Family_relation_bytes, i * 4);
			}
			byte[] message_num_bytes = Encoding.Default.GetBytes(message_num);
			byte[] System_time_bytes = Encoding.Default.GetBytes(System_time);
			return valid_flag_bytes
				.Concat(Family_num_bytes)
				.Concat(Family_msisdn_bytes)
				.Concat(Family_relation_bytes)
				.Concat(message_num_bytes)
				.Concat(System_time_bytes)
				.ToArray();
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			return null;
		}
	}
	/// <summary>
	/// 学生卡读取留言请求
	/// 话机向服务器
	/// </summary>
	[Msg("02", true)]
	public class STDT_READ_MSG_Request : MessageBody
	{
		/// <summary>
		/// 公话手机号 15
		/// </summary>
		public string Device_msisdn { get; set; }
		/// <summary>
		/// 公话ID 18
		/// </summary>
		public string Device_id { get; set; }
		/// <summary>
		/// 学生卡号 18
		/// </summary>
		public string card_id { get; set; }
		/// <summary>
		/// 学生ID 18
		/// </summary>
		public string student_id { get; set; }
		/// <summary>
		/// 请求时间
		/// 14
		/// </summary>
		public string request_time { get; set; }

		public override byte[] GetBytes()
		{
			return null;
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			this.Device_msisdn = Encoding.Default.GetString(bytes, 10, 15);
			this.Device_id = Encoding.Default.GetString(bytes, 25, 18);
			this.card_id = Encoding.Default.GetString(bytes, 43, 18);
			this.student_id = Encoding.Default.GetString(bytes, 61, 18);
			this.request_time = Encoding.Default.GetString(bytes, 79, 14);
			return this;
		}
	}
	/// <summary>
	/// 学生卡读取留言应答
	/// 服务器向话机
	/// </summary>
	[Msg("02", false)]
	public class STDT_READ_MSG_Response : MessageBody
	{
		public List<STDT_MSG_CONTENT> Stdt_Msg_Contents;
		public override byte[] GetBytes()
		{
			int length = 0;
			Stdt_Msg_Contents.ForEach(o =>
			                          {
			                          	length += 4;
			                          	length += o.Message_len;
			                          });
			byte[] bytes = new byte[length];
			int index = 0;

			for (int i = 0; i < Stdt_Msg_Contents.Count; i++)
			{
				Stdt_Msg_Contents[i].GetBytes().CopyTo(bytes, index);
				index += Stdt_Msg_Contents[i].Message_len + 4;
			}
			return bytes;
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			return null;
		}
	}
	/// <summary>
	/// 通话话单请求
	/// 话机向服务器
	/// </summary>
	[Msg("03", true)]
	public class CALL_BILLING_Resquest : MessageBody
	{
		/// <summary>
		/// 公话手机号 15
		/// </summary>
		public string device_msisdn { get; set; }
		/// <summary>
		/// 公话ID 18
		/// </summary>
		public string device_id { get; set; }
		/// <summary>
		/// 学生卡号 18
		/// </summary>
		public string card_id { get; set; }
		/// <summary>
		/// 学生ID 18
		/// </summary>
		public string student_id { get; set; }
		/// <summary>
		/// 话单个数 2
		/// </summary>
		public string Call_times { get; set; }

		public List<CALL_BILLING_CONTENT> Call_Billing_Contents;

		public override byte[] GetBytes()
		{
			return null;
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			this.device_msisdn = GetString(bytes, 10, 15);
			this.device_id = GetString(bytes, 25, 18);
			this.card_id = Utility.ConvertCardID(GetString(bytes, 43, 18));
			this.student_id = GetString(bytes, 61, 18);
			this.Call_times = GetString(bytes, 79, 2);
			int callTimes = Convert.ToInt32(Call_times);
			int index = 81;
			if (Call_Billing_Contents == null)
			{
				Call_Billing_Contents = new List<CALL_BILLING_CONTENT>();
			}
			CALL_BILLING_CONTENT cbc = null;
			for (; callTimes > 0; callTimes--)
			{
				cbc = new CALL_BILLING_CONTENT();
				cbc.start_time = GetString(bytes, index, 14);
				index += 14;
				cbc.called_duration = GetString(bytes, index, 6);
				index += 6;
				cbc.other_party = GetString(bytes, index, 24);
				index += 24;
				Call_Billing_Contents.Add(cbc);
			}
			return this;
		}
	}
	/// <summary>
	/// 通话话单应答
	/// 服务器向话机
	/// </summary>
	[Msg("03", false)]
	public class CALL_BILLING_Response : MessageBody
	{
		/// <summary>
		/// 学生卡是否有效 0 无效 1 有效
		/// </summary>
		public string valid_flag { get; set; }

		public override byte[] GetBytes()
		{
			return Encoding.Default.GetBytes(valid_flag);
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			return null;
		}
	}
	/// <summary>
	/// 学生签到记录请求
	/// </summary>
	[Msg("04", true)]
	public class STDT_SIGN_RECS_Request : MessageBody
	{
		/// <summary>
		/// 公话ID 18
		/// </summary>
		public string device_id { get; set; }


		/// <summary>
		/// 学生卡号 18
		/// </summary>
		protected string card_id { get; set; }

		public string CardID
		{
			get
			{
				return Utility.ConvertCardID(card_id);
			}
		}


		/// <summary>
		/// 学生ID 18
		/// </summary>
		public string student_id { get; set; }
		/// <summary>
		/// 签到时间 14
		/// </summary>
		public string start_time { get; set; }
		public override byte[] GetBytes()
		{
			return null;
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			this.device_id = Encoding.Default.GetString(bytes, 10, 18);
			this.card_id = Encoding.Default.GetString(bytes, 28, 18);
			this.student_id = Encoding.Default.GetString(bytes, 46, 18);
			this.start_time = Encoding.Default.GetString(bytes, 64, 14);
			return this;
		}
	}
	/// <summary>
	/// 学生签到记录应答
	/// </summary>
	[Msg("04", false)]
	public class STDT_SIGN_RECS_Response : MessageBody
	{
		/// <summary>
		/// 学生卡是否有效 0 无效 1 有效
		/// </summary>
		public string valid_flag { get; set; }

		public override byte[] GetBytes()
		{
			return Encoding.Default.GetBytes(valid_flag);
		}


		public override MessageBody FromBytes(byte[] bytes)
		{
			return this;
		}
	}

	/// <summary>
	/// 网络连接状态查询请求
	/// 话机向服务器
	/// </summary>
	[Msg("05", true)]
	public class CONNECT_STATUS_Request : MessageBody
	{
		public override byte[] GetBytes()
		{
			return new byte[] { };
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			return this;
		}
	}
	/// <summary>
	/// 网络连接状态查询应答
	/// 服务器向话机
	/// </summary>
	[Msg("05", false)]
	public class CONNECT_STATUS_Response : MessageBody
	{
		public override byte[] GetBytes()
		{
			return new byte[] { };
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			return this;
		}
	}

	/// <summary>
	/// 发送短消息请求
	/// 话机向服务器
	/// </summary>
	[Msg("06", true)]
	public class SEND_SMS_Request : MessageBody
	{
		/// <summary>
		/// 公话ID 18
		/// </summary>
		public string device_id { get; set; }
		/// <summary>
		/// 学生卡号 18
		/// </summary>
		public string card_id { get; set; }
		/// <summary>
		/// 目标手机号 15
		/// </summary>
		public string Device_msisdn { get; set; }
		/// <summary>
		/// 请求时间 14
		/// </summary>
		public string Request_time { get; set; }
		/// <summary>
		/// 短消息（Asicc编码） 140
		/// </summary>
		public string Sms_Asicc_Cont { get; set; }
		public override byte[] GetBytes()
		{
			return null;
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			this.device_id = Encoding.Default.GetString(bytes, 10, 18);
			this.card_id = Encoding.Default.GetString(bytes, 28, 18);
			this.Device_msisdn = Encoding.Default.GetString(bytes, 46, 15);
			this.Request_time = Encoding.Default.GetString(bytes, 61, 14);
			this.Sms_Asicc_Cont = Encoding.ASCII.GetString(bytes, 75, 140);
			return this;
		}
	}
	/// <summary>
	/// 发送短消息应答
	/// 服务器向话机
	/// </summary>
	[Msg("06", false)]
	public class SEND_SMS_Response : MessageBody
	{
		/// <summary>
		/// 0- 发送失败 1- 发送成功
		/// </summary>
		public string valid_flag { get; set; }

		public override byte[] GetBytes()
		{
			return Encoding.Default.GetBytes(valid_flag);
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			return null;
		}
	}
	/// <summary>
	/// 学号登录请求
	/// </summary>
	[Msg("07", true)]
	public class STDT_NO_LOGIN_Request : MessageBody
	{
		/// <summary>
		/// 公话ID 18
		/// </summary>
		public string device_id { get; set; }
		/// <summary>
		/// 学生ID 18
		/// </summary>
		public string student_id { get; set; }

		/// <summary>
		/// 请求时间 14
		/// </summary>
		public string request_time { get; set; }

		public override byte[] GetBytes()
		{
			return null;
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			this.device_id = Encoding.Default.GetString(bytes, 10, 18);
			this.student_id = Encoding.Default.GetString(bytes, 28, 18);
			this.request_time = Encoding.Default.GetString(bytes, 46, 14);
			return this;
		}
	}
	/// <summary>
	/// 学号登录应答
	/// </summary>
	[Msg("07", false)]
	public class STDT_NO_LOGIN_Response : MessageBody
	{
		/// <summary>
		/// 学号是否有效 0 无效  1 有效
		/// </summary>
		public string valid_flag { get; set; }
		/// <summary>
		/// 亲情号码个数 2
		/// </summary>
		public string Family_num { get; set; }
		/// <summary>
		/// 亲情号码列表 15
		/// </summary>
		public List<string> Family_msisdn { get; set; }
		/// <summary>
		/// 亲情号码关系（汉字形式）4
		/// </summary>
		public List<string> Family_relation { get; set; }
		public override byte[] GetBytes()
		{
			var valid_flag_bytes = Encoding.Default.GetBytes(valid_flag);
			if (valid_flag == "0")
			{
				return valid_flag_bytes;
			}
			else
			{
				var Family_num_bytes = Encoding.Default.GetBytes(Family_num);
				int familyNum = Convert.ToInt32(Family_num);
				byte[] Family_msisdn_bytes = new byte[familyNum * 15];
				byte[] Family_relation_bytes = new byte[familyNum * 4];
				for (int i = 0; i < familyNum; i--)
				{
					Encoding.Default.GetBytes(Family_msisdn[i]).CopyTo(Family_msisdn_bytes, i * 15);
					Encoding.Default.GetBytes(Family_relation[i]).CopyTo(Family_relation_bytes, i * 4);
				}
				return valid_flag_bytes
					.Concat(Family_num_bytes)
					.Concat(Family_msisdn_bytes)
					.Concat(Family_relation_bytes)
					.ToArray();
			}
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			return null;
		}
	}
	/// <summary>
	/// 共话认证请求
	/// </summary>
	[Msg("10", true)]
	public class PHONE_AUTHEN_Request : MessageBody
	{
		public string DeviceId
		{ get; set; }
		public string Reserved
		{ get; set; }

		public override byte[] GetBytes()
		{
			//byte[] bytesDeviceId = Encoding.Default.GetBytes(this.DeviceId);
			//byte[] bytesReserved = Encoding.Default.GetBytes(this.Reserved);
			//return bytesDeviceId.Concat(bytesReserved).ToArray();
			return null;
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			this.DeviceId = Encoding.Default.GetString(bytes, 10, 18);
			this.Reserved = Encoding.Default.GetString(bytes, 28, 8);
			return this;
		}
	}
	/// <summary>
	/// 共话认证应答
	/// </summary>
	[Msg("10", false)]
	public class PHONE_AUTHEN_Response : MessageBody
	{
		/// <summary>
		/// 1
		/// 1:认证成功 0:认证失败
		/// </summary>
		public string valid_flag
		{ get; set; }

		public override byte[] GetBytes()
		{
			return Encoding.Default.GetBytes(valid_flag);
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			valid_flag = Encoding.Default.GetString(bytes, 10, 1);
			return this;
		}
	}

	#region 教师卡拨号验证

	///// <summary>
	///// 教师卡拨号验证请求
	///// </summary>
	//[Msg("74", true)]
	//public class TEACHER_CALL_Request : RequstMessageBody
	//{
	//    public override byte[] GetBytes()
	//    {
	//        throw new NotImplementedException();
	//    }

	//    public override MessageBody FromBytes()
	//    {
	//        throw new NotImplementedException();
	//    }
	//}
	///// <summary>
	///// 教师卡拨号验证应答
	///// </summary>
	//[Msg("74", false)]
	//public class TEACHER_CALL_Response : MessageBody
	//{
	//    public override byte[] GetBytes()
	//    {
	//        throw new NotImplementedException();
	//    }

	//    public override MessageBody FromBytes()
	//    {
	//        throw new NotImplementedException();
	//    }
	//}

	#endregion

	/// <summary>
	/// 程序更新通知请求
	/// 服务器向话机
	/// </summary>
	[Msg("80", false)]
	public class UPDATE_NOTICE_Request : MessageBody
	{
		/// <summary>
		/// 要更新的版本号 18
		/// </summary>
		public string Version { get; set; }
		/// <summary>
		/// 更新程序的长度 6
		/// </summary>
		public string Length { get; set; }

		public override byte[] GetBytes()
		{
			var Version_bytes = Encoding.Default.GetBytes(Version);
			var Length_bytes = Encoding.Default.GetBytes(Length);
			return Version_bytes.Concat(Length_bytes).ToArray();
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			return null;
		}
	}
	/// <summary>
	/// 程序更新通知应答
	/// 话机向服务器
	/// </summary>
	[Msg("80", true)]
	public class UPDATE_NOTICE_Response : MessageBody
	{
		/// <summary>
		/// 目前版本情况 1
		/// 0 目前版本和要更新的版本不一致,要进行更新
		/// 1 目前版本和要更新的版本一致,无需再更新
		/// </summary>
		public string valid_flag { get; set; }
		/// <summary>
		/// 目前公话的版本号 18
		/// </summary>
		public string Version { get; set; }

		public override byte[] GetBytes()
		{
			return null;
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			this.valid_flag = Encoding.Default.GetString(bytes, 10, 1);
			if (this.valid_flag == "0")
			{
				this.Version = Encoding.Default.GetString(bytes, 11, 18);
			}
			return this;
		}
	}
	/// <summary>
	/// 程序更新请求
	/// 服务器向话机
	/// </summary>
	[Msg("81", false)]
	public class UPDATE_PROGRAM_Request : MessageBody
	{
		/// <summary>
		/// 要更新的程序数据 1024
		/// </summary>
		public byte[] Data { get; set; }

		public override byte[] GetBytes()
		{
			return Data;
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			return null;
		}
	}
	/// <summary>
	/// 程序更新应答
	/// 话机向服务器
	/// </summary>
	[Msg("81", true)]
	public class UPDATE_PROGRAM_Response : MessageBody
	{
		/// <summary>
		///  0-	数据接收错误 1-	数据接收正确 1
		/// </summary>
		public string valid_flag { get; set; }

		public override byte[] GetBytes()
		{
			return null;
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			this.valid_flag = Encoding.Default.GetString(bytes, 10, 1);
			return this;
		}
	}
	/// <summary>
	/// 获取公话状态请求
	/// 服务器向话机
	/// </summary>
	[Msg("82", false)]
	public class ABT_STATUS_Request : MessageBody
	{

		private string cur_time;

		/// <summary>
		/// Server端的当前时间
		/// </summary>
		public string Cur_time
		{
			get
			{
				if (string.IsNullOrWhiteSpace(cur_time))
				{
					return DateTime.Now.ToString("yyyyMMddHHmmss");
				}
				return cur_time;
			}
			private set
			{
				cur_time = value;
			}
		}
		public override byte[] GetBytes()
		{
			return Encoding.Default.GetBytes(Cur_time);
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			this.Cur_time = Encoding.Default.GetString(bytes, 10, 14);
			return this;
		}
	}
	/// <summary>
	/// 获取公话状态应答
	/// 话机向服务器
	/// </summary>
	[Msg("82", true)]
	public class ABT_STATUS_Response : MessageBody
	{
		/// <summary>
		/// 设备ID 18
		/// </summary>
		public string Device_id { get; set; }
		/// <summary>
		/// 版本信息 18
		/// 版本信息的格式为 VERx.xx YYYY/MM/DD 例如(VER1.00 2004/05/10)
		/// </summary>
		public string VersionInfo { get; set; }
		/// <summary>
		/// 预留监控信息 72
		/// MinitorInfo前3个字节分别代表市电状态、手柄线状态、外壳门状态
		/// 第1个字节代表市电状态：  1为外电，2为电池供电，3为电池电压低
		/// 第2个字节代表手柄线状态：1为正常状态，2为继线状态
		/// 第3个字节代表外壳门状态：1为关闭状态，2为打开状态
		/// 第55个字节到第72个字节（后18个字节）为短消息版本信息，
		/// 格式为：VERx.xx YYYY/MM/DD 例如(VER1.00 2004/05/10)
		/// </summary>
		public PhoneMinitorInfo MinitorInfo { get; set; }

		public override byte[] GetBytes()
		{
			throw new NotImplementedException();
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			Device_id = Encoding.Default.GetString(bytes, 10, 18);
			VersionInfo = Encoding.Default.GetString(bytes, 28, 18);
			try
			{
				byte[] minitorBytes = new byte[72];
				Array.Copy(bytes, 46, minitorBytes, 0, 72);
				MinitorInfo = PhoneMinitorInfo.Parser(minitorBytes);
			}
			catch
			{
			}
			return this;
		}
	}
	/// <summary>
	/// 读取管理员密码请求
	/// 服务器向话机
	/// </summary>
	[Msg("92", false)]
	public class GET_ADMIN_PWD_Request : MessageBody
	{
		/// <summary>
		/// 公话ID 18
		/// </summary>
		public string device_id { get; set; }
		public override byte[] GetBytes()
		{
			return Encoding.Default.GetBytes(device_id);
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			return null;
		}
	}
	/// <summary>
	/// 读取管理员密码应答
	/// 话机向服务器
	/// </summary>
	[Msg("92", true)]
	public class GET_ADMIN_PWD_Response : MessageBody
	{
		/// <summary>
		/// 1
		/// 0-设备号无效 1-设备号有效
		/// </summary>
		public string Valid_flag { get; set; }
		/// <summary>
		/// 密码内容 10
		/// </summary>
		public string Pwd { get; set; }
		public override byte[] GetBytes()
		{
			return null;
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			this.Valid_flag = Encoding.Default.GetString(bytes, 10, 1);
			if (this.Valid_flag == "1")
			{
				this.Pwd = Encoding.Default.GetString(bytes, 11, 10);
			}
			return this;
		}
	}
	/// <summary>
	/// 设置管理员密码请求
	/// 服务器向话机
	/// </summary>
	[Msg("93", false)]
	public class SET_ADMIN_PWD_Request : MessageBody
	{
		/// <summary>
		/// 公话ID 18
		/// </summary>
		public string device_id { get; set; }
		/// <summary>
		/// 新密码内容 10
		/// </summary>
		public string Pwd { get; set; }
		public override byte[] GetBytes()
		{
			var device_id_bytes = Encoding.Default.GetBytes(device_id);
			var Pwd_bytes = Encoding.Default.GetBytes(Pwd);
			return device_id_bytes.Concat(Pwd_bytes).ToArray();
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			return null;
		}
	}
	/// <summary>
	/// 设置管理员密码应答
	/// 话机向服务器
	/// </summary>
	[Msg("93", true)]
	public class SET_ADMIN_PWD_Response : MessageBody
	{
		/// <summary>
		/// 1
		/// 0-设置失败   1-设置成功
		/// </summary>
		public string Valid_flag { get; set; }
		public override byte[] GetBytes()
		{
			return null;
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			this.Valid_flag = Encoding.Default.GetString(bytes, 10, 1);
			return this;
		}
	}
	/// <summary>
	/// 修改终端设置请求
	/// 服务器向话机
	/// </summary>
	[Msg("94", false)]
	public class EDIT_ABT_SET_Request : MessageBody
	{
		/// <summary>
		/// 是否修改对应的参数
		/// 1 修改
		/// 0 不修改
		/// 第1个字节对应 IP
		/// 第2个字节对应 PORT
		/// 第3个字节对应 ID
		/// </summary>
		public string edit_flag { get; set; }
		/// <summary>
		/// SC IP地址 20
		/// </summary>
		public string sc_ip { get; set; }
		/// <summary>
		/// SC 端口号 10
		/// </summary>
		public string sc_port { get; set; }
		/// <summary>
		/// 终端ID号 18
		/// </summary>
		public string device_id { get; set; }
		public override byte[] GetBytes()
		{
			var edit_flag_bytes = Encoding.Default.GetBytes(edit_flag);
			if (edit_flag == "1")
			{
				var sc_ip_bytes = Encoding.Default.GetBytes(sc_ip);
				var sc_port_bytes = Encoding.Default.GetBytes(sc_port);
				var device_id_bytes = Encoding.Default.GetBytes(device_id);
				return edit_flag_bytes
					.Concat(sc_ip_bytes)
					.Concat(sc_port_bytes)
					.Concat(device_id_bytes)
					.ToArray();
			}
			else
			{
				return edit_flag_bytes;
			}
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			return null;
		}
	}
	/// <summary>
	/// 修改终端设置应答
	/// 话机向服务器
	/// </summary>
	[Msg("94", true)]
	public class EDIT_ABT_SET_Response : MessageBody
	{
		/// <summary>
		/// 1
		/// 0-接收失败  1-接收成功
		/// </summary>
		public string valid_flag { get; set; }
		public override byte[] GetBytes()
		{
			return null;
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			this.valid_flag = Encoding.Default.GetString(bytes, 10, 11);
			return this;
		}
	}

	/// <summary>
	/// 设置终端重启请求
	/// 服务器向话机
	/// </summary>
	[Msg("95", false)]
	public class SET_ABT_RESET_Request : MessageBody
	{
		/// <summary>
		/// 终端号
		/// </summary>
		public string device_id { get; set; }
		public override byte[] GetBytes()
		{
			return Encoding.Default.GetBytes(device_id);
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			return null;
		}
	}

	/// <summary>
	/// 亲情号码更新同步请求
	/// 服务器向话机
	/// </summary>
	[Msg("83", false)]
	public class SYNC_ID_UPDATE_Request : MessageBody
	{
		public override byte[] GetBytes()
		{
			return null;
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			return null;
		}
	}

	/// <summary>
	/// 亲情号码更新同步应答
	/// 话机向服务器
	/// </summary>
	[Msg("83", true)]
	public class SYNC_ID_UPDATE_Response : MessageBody
	{
		/// <summary>
		/// 1
		/// 0-未就绪     1-就绪
		/// </summary>
		public string valid_flag { get; set; }
		public override byte[] GetBytes()
		{
			return null;
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			this.valid_flag = Encoding.Default.GetString(bytes, 10, 1);
			return this;
		}
	}
	/// <summary>
	/// 亲情号码更新发送请求
	/// 服务器向话机
	/// </summary>
	[Msg("84", false)]
	public class SEND_ID_UPDATE_Request : MessageBody
	{
		/// <summary>
		/// 更新数据的条数
		/// 4
		/// </summary>
		public string Data_nums { get; set; }

		public List<FAMILY_MSISDN_CONTENT> Family_Msisdn_contents;
		public override byte[] GetBytes()
		{
			var Data_nums_bytes = Encoding.Default.GetBytes(Data_nums.PadLeft(4, '0'));
			int num = Convert.ToInt32(Data_nums);
			byte[] data = new byte[4 + num * 39];
			Data_nums_bytes.CopyTo(data, 0);
			int index = 4;
			for (int i = 0; i < Family_Msisdn_contents.Count; i++)
			{
				Family_Msisdn_contents[i].GetBytes().CopyTo(data, index);
				index += 39;
			}
			return data;
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			return null;
		}
	}
	/// <summary>
	/// 亲情号码更新发送应答
	/// 话机向服务器
	/// </summary>
	[Msg("84", true)]
	public class SEND_ID_UPDATE_Response : MessageBody
	{
		/// <summary>
		/// 1
		/// 0-接收失败  1-接收成功
		/// </summary>
		public string valid_flag { get; set; }
		public override byte[] GetBytes()
		{
			return null;
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			this.valid_flag = Encoding.Default.GetString(bytes, 10, 1);
			return this;
		}
	}
	/// <summary>
	/// 亲情号码全部删除请求
	/// 服务器向话机
	/// </summary>
	[Msg("85", false)]
	public class ID_DELETE_ALL_Request : MessageBody
	{
		/// <summary>
		/// 1
		/// 0-学生  1-教师
		/// </summary>
		public string Card_type { get; set; }
		public override byte[] GetBytes()
		{
			return Encoding.Default.GetBytes(Card_type);
		}


		public override MessageBody FromBytes(byte[] bytes)
		{
			return null;
		}
	}
	/// <summary>
	/// 亲情号码全部删除应答
	/// 话机向服务器
	/// </summary>
	[Msg("85", true)]
	public class ID_DELETE_ALL_Response : MessageBody
	{
		/// <summary>
		/// 1
		/// 0-删除失败   1-删除成功
		/// </summary>
		public string valid_flag { get; set; }
		public override byte[] GetBytes()
		{
			return null;
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			this.valid_flag = Encoding.Default.GetString(bytes, 10, 1);
			return this;
		}
	}
	/// <summary>
	/// 亲情号码部分删除请求
	/// 服务器向话机
	/// </summary>
	[Msg("86", false)]
	public class ID_DELETE_ONE_Request : MessageBody
	{
		/// <summary>
		/// 1
		/// 0-学生  1-教师
		/// </summary>
		public string Card_type { get; set; }
		/// <summary>
		/// 卡号
		/// 18
		/// </summary>
		public string card_id { get; set; }

		public override byte[] GetBytes()
		{
			return Encoding.Default.GetBytes(Card_type)
				.Concat(Encoding.Default.GetBytes(card_id))
				.ToArray();
		}


		public override MessageBody FromBytes(byte[] bytes)
		{
			return null;
		}
	}
	/// <summary>
	/// 亲情号码部分删除应答
	/// 话机向服务器
	/// </summary>
	[Msg("86", true)]
	public class ID_DELETE_ONE_Response : MessageBody
	{

		/// <summary>
		/// 1
		/// 0-删除失败   1-删除成功
		/// </summary>
		public string valid_flag { get; set; }
		public override byte[] GetBytes()
		{
			return null;
		}


		public override MessageBody FromBytes(byte[] bytes)
		{
			this.valid_flag = Encoding.Default.GetString(bytes, 10, 1);
			return this;
		}
	}
	/// <summary>
	/// 更新短消息类型请求
	/// 服务器向话机
	/// </summary>
	[Msg("89", false)]
	public class UPDATE_SMS_TYPE_Request : MessageBody
	{
		/// <summary>
		/// 短消息类型号 2
		/// </summary>
		public string Sms_type { get; set; }
		/// <summary>
		/// 1
		/// 1-更新(增加)  2-删除
		/// </summary>
		public string Type { get; set; }
		/// <summary>
		/// 短消息类型提示内容
		/// 12
		/// </summary>
		public string Sms_type_text { get; set; }

		public override byte[] GetBytes()
		{
			return Encoding.Default.GetBytes(Sms_type)
				.Concat(Encoding.Default.GetBytes(this.Type))
				.Concat(Encoding.Default.GetBytes(Sms_type_text))
				.ToArray();
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			return null;
		}
	}
	/// <summary>
	/// 更新短消息类型应答
	/// 话机向服务器
	/// </summary>
	[Msg("89", true)]
	public class UPDATE_SMS_TYPE_Response : MessageBody
	{
		/// <summary>
		/// 1
		/// 0-更新失败   1-更新成功
		/// </summary>
		public string Valid_flag { get; set; }
		/// <summary>
		/// 短消息类型号
		/// 2
		/// </summary>
		public string Sms_type { get; set; }
		public override byte[] GetBytes()
		{
			return null;
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			this.Valid_flag = Encoding.Default.GetString(bytes, 10, 1);
			this.Sms_type = Encoding.Default.GetString(bytes, 11, 2);
			return this;
		}
	}
	/// <summary>
	/// 更新短消息内容请求
	/// 服务器向话机
	/// </summary>
	[Msg("90", false)]
	public class UPDATE_SMS_Request : MessageBody
	{
		/// <summary>
		/// 短消息类型号
		/// 2
		/// </summary>
		public string Sms_type { get; set; }
		/// <summary>
		/// 短消息索引号
		/// 2
		/// </summary>
		public string Sms_id { get; set; }

		/// <summary>
		/// 1-更新(增加)  2-删除
		/// 1
		/// </summary>
		public string Type { get; set; }

		#region

		///// <summary>
		///// 短消息内容（asicc字符）
		///// 140
		///// </summary>
		//public string Sms_Text_Cont { get; set; }
		///// <summary>
		///// 短消息内容（unicode编码）
		///// 140
		///// </summary>
		//public string Sms_Unicode_Cont { get; set; }

		#endregion

		/// <summary>
		/// 短信息内容
		/// 需要asicc编码和Unicode编码
		/// 140
		/// </summary>
		public string Sms_Cont { get; set; }
		public override byte[] GetBytes()
		{
			return Encoding.Default.GetBytes(Sms_type)
				.Concat(Encoding.Default.GetBytes(Sms_id))
				.Concat(Encoding.Default.GetBytes(this.Type))
				.Concat(Encoding.ASCII.GetBytes(Sms_Cont))
				.Concat(Encoding.Unicode.GetBytes(Sms_Cont))
				.ToArray();
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			return null;
		}
	}
	/// <summary>
	/// 更新短消息内容应答
	/// 话机向服务器
	/// </summary>
	[Msg("90", true)]
	public class UPDATE_SMS_Response : MessageBody
	{
		/// <summary>
		/// 0-更新失败   1-更新成功
		/// 1
		/// </summary>
		public string Valid_flag { get; set; }
		/// <summary>
		/// 短消息类型号 2
		/// </summary>
		public string Sms_type { get; set; }
		/// <summary>
		/// 短消息索引号 2
		/// </summary>
		public string Sms_id { get; set; }

		public override byte[] GetBytes()
		{
			return null;
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			this.Valid_flag = Encoding.Default.GetString(bytes, 10, 1);
			this.Sms_type = Encoding.Default.GetString(bytes, 11, 2);
			this.Sms_id = Encoding.Default.GetString(bytes, 13, 2);
			return this;
		}
	}
	/// <summary>
	/// 更新短消息版本号请求
	/// 服务器向话机
	/// </summary>
	[Msg("91", false)]
	public class SET_SMS_VER_Request : MessageBody
	{
		/// <summary>
		/// 短消息版本号 18
		/// </summary>
		public string Version { get; set; }
		public override byte[] GetBytes()
		{
			return Encoding.Default.GetBytes(Version);
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			return null;
		}
	}
	/// <summary>
	/// 更新短消息版本号应答
	/// 话机向服务器
	/// </summary>
	[Msg("91", true)]
	public class SET_SMS_VER_Response : MessageBody
	{
		/// <summary>
		/// 1
		/// 0-更新失败   1-更新成功
		/// </summary>
		public string Valid_flag { get; set; }

		public override byte[] GetBytes()
		{
			return null;
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			this.Valid_flag = Encoding.Default.GetString(bytes, 10, 1);
			return this;
		}
	}
	/// <summary>
	/// 卡信息更新同步请求
	/// 服务器向话机
	/// </summary>
	[Msg("75", false)]
	public class SYNC_CARD_INFO_UPDATE_Request : MessageBody
	{

		public override byte[] GetBytes()
		{
			throw new NotImplementedException();
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			throw new NotImplementedException();
		}
	}
	/// <summary>
	/// 卡信息更新同步应答
	/// 话机向服务器
	/// </summary>
	[Msg("75", true)]
	public class SYNC_CARD_INFO_UPDATE_Response : MessageBody
	{
		/// <summary>
		/// 1
		/// 0-未就绪     1-就绪
		/// </summary>
		public string valid_flag { get; set; }
		public override byte[] GetBytes()
		{
			throw new NotImplementedException();
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			throw new NotImplementedException();
		}
	}
	/// <summary>
	/// 卡信息更新发送请求
	/// 服务器向话机
	/// </summary>
	[Msg("76", false)]
	public class SEND_CARD_INFO_UPDATE_Request : MessageBody
	{
		/// <summary>
		/// 更新数据的条数
		/// 4
		/// </summary>
		public string Data_nums { get; set; }

		public List<CARD_INFO_CONTENT> Card_Info_Contents;

		public override byte[] GetBytes()
		{
			throw new NotImplementedException();
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			throw new NotImplementedException();
		}
	}
	/// <summary>
	/// 卡信息更新发送应答
	/// 话机向服务器
	/// </summary>
	[Msg("76", true)]
	public class SEND_CARD_INFO_UPDATE_Response : MessageBody
	{
		/// <summary>
		/// 1
		/// 0-接收失败  1-接收成功
		/// </summary>
		public string valid_flag { get; set; }
		public override byte[] GetBytes()
		{
			throw new NotImplementedException();
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			throw new NotImplementedException();
		}
	}
	/// <summary>
	/// 卡信息全部删除请求
	/// 服务器向共话
	/// </summary>
	[Msg("77", false)]
	public class CARD_INFO_DELETE_ALL_Request : MessageBody
	{
		/// <summary>
		/// 卡属性
		/// 1
		/// 卡属性为０时，删除所有学生的卡信息；
		/// 卡属性为１时，删除所有教师的卡信息；
		/// 卡属性为2时，删除家长卡信息；……
		/// </summary>
		public string Card_type { get; set; }
		public override byte[] GetBytes()
		{
			throw new NotImplementedException();
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			throw new NotImplementedException();
		}
	}
	/// <summary>
	/// 卡信息全部删除应答
	/// 话机向服务器
	/// </summary>
	[Msg("77", true)]
	public class CARD_INFO_DELETE_ALL_Response : MessageBody
	{
		/// <summary>
		/// /
		/// 0-删除失败   1-删除成功
		/// </summary>
		public string valid_flag { get; set; }
		public override byte[] GetBytes()
		{
			throw new NotImplementedException();
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			throw new NotImplementedException();
		}
	}
	/// <summary>
	/// 卡信息部分删除请求
	/// 服务器向话机
	/// </summary>
	[Msg("78", false)]
	public class CARD_INFO_DELETE_ONE_Request : MessageBody
	{

		/*
		 * 卡属性为０时，删除指定学生的卡信息；
		 * 卡属性为１，删除指定教师的卡信息；
		 * 卡属性为2时，删除指定家长卡信息；……
		 */

		/// <summary>
		/// 卡属性
		/// 1
		/// </summary>
		public string Card_type { get; set; }
		/// <summary>
		/// 卡号
		/// 18
		/// </summary>
		public string card_id { get; set; }

		public override byte[] GetBytes()
		{
			throw new NotImplementedException();
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			throw new NotImplementedException();
		}
	}
	/// <summary>
	/// 卡信息部分删除应答
	/// 话机向服务器
	/// </summary>
	[Msg("78", true)]
	public class CARD_INFO_DELETE_ONE_Response : MessageBody
	{
		/// <summary>
		/// 1
		/// 0-删除失败   1-删除成功
		/// </summary>
		public string valid_flag { get; set; }

		public override byte[] GetBytes()
		{
			throw new NotImplementedException();
		}

		public override MessageBody FromBytes(byte[] bytes)
		{
			throw new NotImplementedException();
		}
	}

	/// <summary>
	/// 话单内容
	/// </summary>
	public class CALL_BILLING_CONTENT
	{
		/// <summary>
		/// 开始呼叫时间 14
		/// </summary>
		public string start_time { get; set; }
		/// <summary>
		/// 通话时长 6
		/// </summary>
		public string called_duration { get; set; }
		/// <summary>
		/// 被叫号码 24
		/// </summary>
		public string other_party { get; set; }
	}
	/// <summary>
	/// 留言内容
	/// </summary>
	public class STDT_MSG_CONTENT
	{
		/// <summary>
		/// 留言长度 1
		/// </summary>
		public int Message_len
		{
			get
			{
				return Utility.GetStringLength(Message);
			}
			set
			{
				Message_len = value;
			}
		}
		/// <summary>
		/// 留言内容
		/// </summary>
		public string Message { get; set; }

		public byte[] GetBytes()
		{
			return Encoding.Default.GetBytes(Message_len.ToString().PadLeft(4, '0'))
				.Concat(Encoding.Default.GetBytes(Message))
				.ToArray();
		}
	}
	/// <summary>
	/// 亲情号码
	/// </summary>
	public class FAMILY_MSISDN_CONTENT
	{
		/*
		 * 注：如果要传输的数据量较大，则进行分次传输。
		 * 一次传输的数据条数不大于20条（数据包大小控制在1K内）
		 */

		/// <summary>
		/// 数据的处理方式  1
		/// 0-删除  1-增加
		/// </summary>
		public string type { get; set; }
		/// <summary>
		/// 卡号  18
		/// </summary>
		public string card_id { get; set; }
		/// <summary>
		/// 卡属性 1
		/// 0-学生  1-教师
		/// </summary>
		public string card_type { get; set; }
		/// <summary>
		/// 亲情号码 15
		/// </summary>
		public string Family_msisdn { get; set; }
		/// <summary>
		/// 亲情号码关系（汉字形式）
		/// </summary>
		public string Family_relation { get; set; }

		public Byte[] GetBytes()
		{
			return Encoding.Default.GetBytes(type)
				.Concat(Encoding.Default.GetBytes(card_id))
				.Concat(Encoding.Default.GetBytes(card_type))
				.Concat(Encoding.Default.GetBytes(Family_msisdn))
				.Concat(Encoding.Default.GetBytes(Family_relation))
				.ToArray();
		}
	}
	/// <summary>
	/// 卡信息
	/// </summary>
	public class CARD_INFO_CONTENT
	{
		/*
		 * *1.	如果要传输的数据量较大，则进行分次传输。
		 * 一次传输的数据条数不大于20条（数据包大小控制在1K内）。
		 * 
		 * 2.	当tone_type为0-2时，不需要下发6、7字段；
		 * 仅当tone_type为3-TTS播报时，才下发6、7字段，用于TTS播报内容。
		 */

		/// <summary>
		/// 数据的处理方式
		/// 1
		/// 1- 增加(卡ID存在就修改)
		/// 2- 修改(卡ID不存在就添加)
		/// </summary>
		public string type { get; set; }
		/// <summary>
		/// 卡号 18
		/// </summary>
		public string card_id { get; set; }
		/// <summary>
		/// 卡属性：（下同）
		/// 1
		/// 0-	学生
		/// 1-	教师
		/// 2-	家长
		/// 3-	住宿生
		/// 4-	走读生
		/// </summary>
		public string card_type { get; set; }

		/// <summary>
		/// 1
		/// 0-	无提示
		/// 1-	短提示音
		/// 2-	长提示音
		/// 3-	TTS播报(需购买硬件支持)
		/// </summary>
		public string tone_type { get; set; }
		/// <summary>
		/// TTS播报内容“xxx的家长”，由平台生成
		/// 30
		/// </summary>
		public string tone_info { get; set; }
		/// <summary>
		/// 保留字段
		/// 10
		/// </summary>
		public string Reserve { get; set; }
	}

	/// <summary>
	/// 预留监控信息 72
	/// MinitorInfo前3个字节分别代表市电状态、手柄线状态、外壳门状态
	/// 第1个字节代表市电状态：  1为外电，2为电池供电，3为电池电压低
	/// 第2个字节代表手柄线状态：1为正常状态，2为继线状态
	/// 第3个字节代表外壳门状态：1为关闭状态，2为打开状态
	/// 第55个字节到第72个字节（后18个字节）为短消息版本信息，
	/// 格式为：VERx.xx YYYY/MM/DD 例如(VER1.00 2004/05/10)
	/// </summary>
	public class PhoneMinitorInfo
	{
		/// <summary>
		/// 表市电状态：  1为外电，2为电池供电，3为电池电压低
		/// </summary>
		public string SDStatus { get; set; }
		/// <summary>
		/// 手柄线状态：1为正常状态，2为继线状态
		/// </summary>
		public string SBXStatus { get; set; }
		/// <summary>
		/// 外壳门状态：1为关闭状态，2为打开状态
		/// </summary>
		public string WKMStatus { get; set; }
		/// <summary>
		/// 第55个字节到第72个字节（后18个字节）为短消息版本信息，
		/// 格式为：VERx.xx YYYY/MM/DD 例如(VER1.00 2004/05/10)
		/// </summary>
		public string SMSVER { get; set; }

		public static PhoneMinitorInfo Parser(byte[] bytes)
		{
			PhoneMinitorInfo info = new PhoneMinitorInfo();
			info.SDStatus = System.Text.Encoding.Default.GetString(bytes, 0, 1);
			info.SBXStatus = System.Text.Encoding.Default.GetString(bytes, 1, 1);
			info.WKMStatus = System.Text.Encoding.Default.GetString(bytes, 2, 1);
			info.SMSVER = System.Text.Encoding.Default.GetString(bytes, 54, 72);
			return info;
		}

	}

}
